package com.hj.excel.handler;

import com.hj.excel.config.ColumnConfig;
import org.apache.poi.ss.usermodel.Cell;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * @author hj
 * @Date 2022/1/4
 * @Description: 错误行默认处理
 */
public class CollectErrorRowHandler implements ErrorRowHandler<Object> {

    private final List<CellData> errorData = new ArrayList<>();

    @Override
    public boolean handlerRow(Cell cell, Method writeMethod, ColumnConfig<Object,Object> columnConfig) {
        CellData cellData = new CellData(cell.getRowIndex(),
                cell.getColumnIndex(), cell.getStringCellValue(), columnConfig);
        errorData.add(cellData);
        System.out.println(cellData);
        return true;
    }

    static class CellData {
        private int rowIndex;
        private int cellIndex;
        private String cellValue;
        private ColumnConfig<Object,Object> columnConfig;

        public CellData() {
        }

        public CellData(int rowIndex, int cellIndex, String cellValue, ColumnConfig<Object,Object> columnConfig) {
            this.rowIndex = rowIndex;
            this.cellIndex = cellIndex;
            this.cellValue = cellValue;
            this.columnConfig = columnConfig;
        }

        public int getRowIndex() {
            return rowIndex;
        }

        public void setRowIndex(int rowIndex) {
            this.rowIndex = rowIndex;
        }

        public int getCellIndex() {
            return cellIndex;
        }

        public void setCellIndex(int cellIndex) {
            this.cellIndex = cellIndex;
        }

        public String getCellValue() {
            return cellValue;
        }

        public void setCellValue(String cellValue) {
            this.cellValue = cellValue;
        }

        public ColumnConfig<Object,Object> getColumnConfig() {
            return columnConfig;
        }

        public void setColumnConfig(ColumnConfig<Object,Object> columnConfig) {
            this.columnConfig = columnConfig;
        }
    }

    public List<CellData> getErrorData() {
        return errorData;
    }


}
